/*
 * @Author: 刘经标 2604132672@qq.com
 * @Date: 2025-04-15 10:10:04
 * @LastEditors: 刘经标 2604132672@qq.com
 * @LastEditTime: 2025-05-09 17:12:21
 * @FilePath: /ai-assistant-frontend/src/services/api.ts
 * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
 */
import axios from 'axios';

const API_BASE_URL = process.env.REACT_APP_API_BASE_URL || 'http://localhost:3000/api';

export const sendMessage = async (messages: Array<{role: string, content: string}>) => {
  try {
    const response = await axios.post(`${API_BASE_URL}/chat`, {
      messages
    }, {
      headers: {
        'Content-Type': 'application/json',
      },
      timeout: 30000,
    });
    return response.data.choices[0].message.content;
  } catch (error) {
    console.error('API Error:', error);
    throw error;
  }
};

export const checkHealth = async () => {
  const response = await axios.get(`${API_BASE_URL}/health`);
  return response.data;
};